<template>
    <div class="goodsList_box">
        <div class="goodItem" v-for="item in goodList" :key="item.id" @click="goDeial(item.id)">
            <img :src="item.img_url" alt="">
            <h2 class="title">{{item.title}}</h2>
            <div class="introduce">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <del>￥{{item.market_price}}</del>
                </p>
                <p class="cell">热卖中 <span>剩余{{item.stock_quantity}}件</span></p>
            </div>
        </div>
        <mt-button type="danger" size='large' @click="addMore">点击加载更多</mt-button>
    </div>
</template>
<script>
export default {
    data(){
        return{
            num:1,
            goodList:[]
        }
    },
    created(){
       this.getgoodList()
    },
    methods:{
        getgoodList(){
            this.$http.get('api/getgoods?pageindex=' + this.num).then( res => {
                if (res.body.status == 0){
                    this.goodList =  this.goodList.concat(res.body.message)
                }
            })
        },
        addMore(){
            this.num++
            this.getgoodList()
        },
        goDeial(id){
            this.$router.push('/home/goodsInfo/'+ id)
        }
    }
}
</script>
<style lang="scss" scoped>
.goodsList_box {
    padding: 7px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .goodItem {
        width: 49%;
        padding: 2px;
        border:1px solid #ccc;
        box-shadow: 0 0 8px #ccc;
        margin: 4px 0;
        min-height: 293px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        img {
            width: 100%;
        }
        .title {
            font-size: 14px;
            color: #000;

        }
        .introduce {
            background-color: #eee;
            .price {
                margin: 0;
                padding: 5px;
                span{
                    font-size: 16px;
                    color: red;
                    font-weight: 700;
                    margin-right: 5px;
                }
                del{
                    font-size: 12px;
                }
            }
            .cell {
                font-size: 13px;
                display:flex;
                justify-content: space-between;
                padding: 5px;
                margin: 0;
            }
        }
    }
}
</style>
